﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace guest_management_in_a_hotel
{
    public partial class FrmThongTinTK : Form
    {
        SqlConnection conn;
        SqlCommand cmd;
        SqlDataReader rd;
        int sphong;
        public FrmThongTinTK()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FrmTimKiemPhong frmtk = new FrmTimKiemPhong();
            frmtk.Show();
            this.Hide();
        }

        private void FrmThongTinTK_Load(object sender, EventArgs e)
        {
            int Room_No = Int32.Parse(FrmTimKiemPhong.sophong);
            conn = Connect.getConnection();
            try
            {
                conn.Open();
                String strsql = "select Room_Number,Room_Type,Room_Description,Price_Per_Day,status from TblRooms where Room_Number='"+Room_No+"'";
                cmd = new SqlCommand(strsql, conn);
                rd = cmd.ExecuteReader();
                if (rd.Read())
                {
                    sphong = rd.GetInt32(0);
                    tbsophong.Text = rd.GetInt32(0).ToString();
                    tbkieuphong.Text = rd.GetString(1);
                    tbghichu.Text = rd.GetString(2);
                    tbgia.Text = rd.GetDecimal(3).ToString();
                    tbtinhtrang.Text = rd.GetString(4);
                    
                }
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
            conn.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            conn = Connect.getConnection();
            try
            {
                if (conn != null)
                {
                    conn.Open();
                    String strsql = "UPDATE TblRooms SET Room_Number='"+Int32.Parse(tbsophong.Text)+"',Room_Type=N'"+tbkieuphong.Text+"',Room_Description=N'"+tbghichu.Text+"',Price_Per_Day='"+Int32.Parse(tbgia.Text)+"',status=N'"+tbtinhtrang.Text+"' where Room_Number='"+sphong+"'";
                    
                    cmd = new SqlCommand(strsql, conn);
                    rd = cmd.ExecuteReader();
                    conn.Close();

                    FrmTimKiemPhong frmtkp = new FrmTimKiemPhong();
                    frmtkp.Show();
                    this.Hide();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Lỗi sửa thông tin phòng", "Mời nhập lại");

            }
        }
    }
}
